#include <stdio.h>
#include <stdlib.h>
#include <sys/mmap.h>

unsigned int root,head;
const unsigned int block_size=16*1024;

void *open_tree(char *db_name,unsigned int size,int create)
{
        int fd,flag;
        if (create != 0)
                flag=O_RDWR|O_CREAT|O_TRUNC;
        else
                flag=O_RDWR;
        if((fd=open(db_name,flag,S_IRWXU)) < 0)
        {
                perror("open");
                return NULL;
        }
        if(ftruncate(fd,size) != 0)
        {
                perror("ftruncate");
                return NULL;
        }
        if((m=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0)) == MAP_FAILED)
        {
                perror("mmap");
                return NULL;
        }
        close(fd);
        return m;
}

void init_tree(void *m)
{
	root=0;
	head=0;
	alloc_block(block_size);
}
unsigned int alloc_block(int size)
{
	memset(head,0,block_size);
	head+=size;
	return head-size;
}

void insert_tree(void *m,void *data)
{
	
}

void *search_block(
int main(int argc,char **argv)
{
	return 0;
}
